app.controller('NotifysCtrl', function ($scope, ajax, $stateParams, toaster) {

	var inserter = new Req.POST({ resource: $scope.resource });

	$scope.dplist = [];
	$scope.loaddplist = function () {
		$scope.dplist = [
			{ id: 0, name: "客服消息" },
			{ id: 1, name: "订票消息" },
			{ id: 2, name: "城际约租消息" },
			{ id: 3, name: "跨城巴士消息" }
		];
		$scope.dplist.selected = $scope.dplist[0];
	};
	$scope.loaddplist();

	$scope.list = [];

	$scope.clear = function () {
		$scope.subject = "";
		$scope.content = "";
	};

	$scope.send = function () {
		if ($scope.dplist.selected.id == 0) {
			if ($scope.subject == undefined || $scope.subject == null) {
				toaster.pop('warning', '提示', '标题不可为空！');
			}
			if ($scope.content == undefined || $scope.content == null) {
				toaster.pop('warning', '提示', '内容不可为空并且在200字以内！');
			}
			if ($scope.myForm.$valid) {
				$scope.type = 1;
				inserter.fields = { "subject": $scope.subject, "content": $scope.content };
				inserter.resource = 'notify/' + $scope.loginUser.id + '/' + $scope.type + '/broadcast';
				ajax.call(inserter).then(function (result) {
					if (result.code == 200) {
						toaster.pop('success', '成功', '发送消息成功。');
					} else {
						toaster.pop('error', '错误', '发送消息失败！');
					}
				}, function () { toaster.pop('error', '错误', '发送消息失败！'); });
			}
		} else {
			toaster.pop('warning', '提示', '请选择收件人！');
		}
	};

});
